﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefEquipment" :model="stateEquipment.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_EquipName_FormItem" prop="Entity.EquipName"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_EquipName')}), trigger: 'blur' }]"
											:label="$t('message.autotrans._Model_Equipment_EquipName')">
            <el-input v-model="stateEquipment.vmModel.Entity.EquipName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_EquipCode_FormItem" prop="Entity.EquipCode"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_EquipCode')}), trigger: 'blur' }]"
											:label="$t('message.autotrans._Model_Equipment_EquipCode')">
            <el-input v-model="stateEquipment.vmModel.Entity.EquipCode" clearable></el-input>
        </el-form-item>

        </el-col>
				<el-col :xs="24" :lg="12" class="mb20">
					<el-form-item ref="Entity_EquipType_FormItem" prop="Entity.EquipType"
												:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_EquipType')}), trigger: 'blur' }]"
												:label="$t('message.autotrans._Model_Equipment_EquipType')">
						<el-select v-model="stateEquipment.vmModel.Entity.EquipType" clearable>
							<el-option key="Equipment" value="Equipment" :label="$t('message.autotrans._Enum_EquipTypeEnum_Equipment')"></el-option>
							<el-option key="Tooling" value="Tooling" :label="$t('message.autotrans._Enum_EquipTypeEnum_Tooling')"></el-option>
							<el-option key="Mould" value="Mould" :label="$t('message.autotrans._Enum_EquipTypeEnum_Mould')"></el-option>
						</el-select>
					</el-form-item>

				</el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_SpotType_FormItem" prop="Entity.SpotType" :label="$t('message.autotrans._Model_Equipment_SpotType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_SpotType')}), trigger: 'blur' }]" >
            <el-select v-model="stateEquipment.vmModel.Entity.SpotType" clearable>
               <el-option key="Barcode" value="Barcode" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_Barcode')"></el-option>
               <el-option key="Itemized" value="Itemized" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_Itemized')"></el-option>
               <el-option key="None" value="None" :label="$t('message.autotrans._Enum_EquipSpotCheckEnum_None')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DriverType_FormItem" prop="Entity.DriverType" :label="$t('message.autotrans._Model_Equipment_DriverType')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_Equipment_DriverType')}), trigger: 'blur' }]" >
            <el-select v-model="stateEquipment.vmModel.Entity.DriverType" clearable>
               <el-option key="OpcUa" value="OpcUa" :label="$t('message.autotrans._Enum_DriverTypeEnum_OpcUa')"></el-option>
               <el-option key="None" value="None" :label="$t('message.autotrans._Enum_DriverTypeEnum_None')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
         <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DriverGroup_FormItem" prop="Entity.DriverGroup" :label="$t('message.autotrans._Model_Equipment_DriverGroup')" >
         
           <el-input v-model="stateEquipment.vmModel.Entity.DriverGroup" clearable></el-input>
        
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IpAddress_FormItem" prop="Entity.IpAddress" :label="$t('message.autotrans._Model_Equipment_IpAddress')">
            <el-input v-model="stateEquipment.vmModel.Entity.IpAddress" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Port_FormItem" prop="Entity.Port" :label="$t('message.autotrans._Model_Equipment_Port')">
            <el-input-number v-model="stateEquipment.vmModel.Entity.Port" clearable></el-input-number>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Actvie_FormItem" prop="Entity.Actvie" :label="$t('message.autotrans._Model_Equipment_Actvie')">
            <el-select v-model="stateEquipment.vmModel.Entity.Actvie" clearable>
               <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
               <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Manufactor_FormItem" prop="Entity.Manufactor" :label="$t('message.autotrans._Model_Equipment_Manufactor')">
            <el-input v-model="stateEquipment.vmModel.Entity.Manufactor" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <WtmTable ref="tableRefEquipmentTagEquipmentList" v-bind="tableDataEquipmentTagEquipmentList" v-model="stateEquipment.vmModel.Entity.EquipmentTag_Equipment"></WtmTable>
      <div style="text-align:right;">
        <WtmButton @click="onSubmitEquipment"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseEquipment"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementEquipmentCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { equipmentApi } from '/@/api/equipmentmanagement/equipment';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const tableRefEquipmentTagEquipmentList = ref();
const tableDataEquipmentTagEquipmentList = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page变量名称'),key: 'TagName',type: 'textbox',isCheck: true,colWidth:150},
      {title:ci.proxy.$t('message.autotrans.Page描述'),key: 'Description',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminAddress'),key: 'Address',type: 'textbox',isCheck: true,colWidth:200},
      {title:ci.proxy.$t('message.autotrans.Page变量类型'),key: 'TagType',type: 'combobox',colWidth:200,comboData:{
                Alarm:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Alarm'),
                Equipment_State:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Equipment_State'),
                Equipment_Mode:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Equipment_Mode'),
                Entry_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Entry_Sign'),
                Entry_SN:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Entry_SN'),
                Entry_Formual:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Entry_Formual'),
                Entry_Rfid:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Entry_Rfid'),
                Archive_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Sign'),
                Archive_SN:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_SN'),
                Archive_Status:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Status'),
                Archive_Formual:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Formual'),
                Archive_Operator:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Operator'),
                Archive_Shift:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Shift'),
                Archive_Rfid:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_Rfid'),
                Archive_CycleTime:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Archive_CycleTime'),
                Scan_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Scan_Sign'),
                Scan_Barcode:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Scan_Barcode'),
                Scan_Step:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Scan_Step'),
                ScanBatch_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_ScanBatch_Sign'),
                ScanBatch_Formual:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_ScanBatch_Formual'),
                ScanBatch_01_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_ScanBatch_01_Sign'),
                ScanBatch_02_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_ScanBatch_02_Sign'),
                ScanBatch_Barcode:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_ScanBatch_Barcode'),
                TakePartIn_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_TakePartIn_Sign'),
                TakePartIn_SN:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_TakePartIn_SN'),
                SpotCheck_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_SpotCheck_Sign'),
                SpotCheck_01_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_SpotCheck_01_Sign'),
                SpotCheck_02_Sign:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_SpotCheck_02_Sign'),
                SpotCheck_Barcode:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_SpotCheck_Barcode'),
                PLC_Heartbeat:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_PLC_Heartbeat'),
                Parameter:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Parameter'),
                Result:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_Result'),
                RealTimeData:ci.proxy.$t('message.autotrans._Enum_TagDefineEnum_RealTimeData'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据类型'),key: 'DataType',colWidth:150,type: 'combobox',comboData:{
                Sys_Bit:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Bit'),
                Sys_Byte:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Byte'),
                Sys_Word:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Word'),
                Sys_DWord:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DWord'),
                Sys_Int:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Int'),
                Sys_DInt:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_DInt'),
                Sys_Real:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_Real'),
                Sys_LReal:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_LReal'),
                Sys_String:ci.proxy.$t('message.autotrans._Enum_TagDataTypeEnum_Sys_String'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page扫描速率'),key: 'ScanRate',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page信号组'),key: 'GroupType',colWidth:150,type: 'combobox',comboData:{
                Entry:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_Entry'),
                Archive:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_Archive'),
                Rewrok:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_Rewrok'),
                NG:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_NG'),     
                 ScanKey:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_ScanKey'),
              ScanBatch:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_ScanBatch'),
                None:ci.proxy.$t('message.autotrans._Enum_TagGroupEnum_None'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page访问模式'),key: 'AccessMode',colWidth:150,type: 'combobox',comboData:{
                Read:ci.proxy.$t('message.autotrans._Enum_TagAccessModeEnum_Read'),
                Write:ci.proxy.$t('message.autotrans._Enum_TagAccessModeEnum_Write'),
                ReadWrite:ci.proxy.$t('message.autotrans._Enum_TagAccessModeEnum_ReadWrite'),},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page上限'),key: 'UpLimit',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page下限'),key: 'LowerLimit',type: 'textbox',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page激活'),key: 'Active',type: 'switch',comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page激活上下限'),key: 'ActiveLimit',colWidth:150,type: 'switch',comboData:
                {true:ci.proxy.$t('message._system.common.vm.tips_bool_true'),
                  false:ci.proxy.$t('message._system.common.vm.tips_bool_false')},isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: false, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
        isSub:true,
        isDisabled:false
	}
});

// 定义变量内容
const formRefEquipment = ref();
const stateEquipment = reactive({
    vmModel: {
	  Entity:{
        EquipName: '',
        EquipCode: '',
        EquipType: undefined,
        SpotType: undefined,
        DriverType: undefined,
        IpAddress: '',
        DriverGroup:'',
        Port: '',
        Actvie: true,
        Manufactor: '',
        EquipmentTag_Equipment:[],
      },

	},
    
    AllEquipments: [] as any[],
});

// 取消
const onCloseEquipment = () => {
    closeDialog();
};

// 提交
const onSubmitEquipment = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefEquipment.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            equipmentApi().add(stateEquipment.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/EquipmentManagement/EquipmentTag/GetEquipments',[],false).then(x=>{stateEquipment.AllEquipments = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

